package com.example.service.impl;

import com.example.entity.Dept;
import com.example.entity.example.DeptExample;
import com.example.mapper.DeptMapper;
import com.example.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DeptServiceImpl implements DeptService {
    @Autowired(required = false)
    DeptMapper deptMapper;

    @Override
    public List<Dept> getByExampleWithLimit(DeptExample example, Integer curPage, Integer pageSize) {
        int begin = (curPage - 1) * pageSize;
        return deptMapper.selectByExampleWithLimit(example, begin, pageSize);
    }

    @Override
    public long getCountByExample(DeptExample example) {
        return deptMapper.countByExample(example);
    }

    @Override
    public void addDept(Dept dept) {
        deptMapper.insert(dept);
    }

    @Override
    public String getNameById(Integer deptId) {
        return deptMapper.selectByPrimaryKey(deptId).getDname();
    }

    @Override
    public void removeById(Integer id) {
        deptMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void updateById(Dept dept) {
        deptMapper.updateByPrimaryKey(dept);
    }
}
